<?php include './application/views/top.php'; ?>
<script src="/static/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="/static/js/formCheck.js"></script>
<script type="text/javascript" src="/static/js/My97DatePicker/WdatePicker.js"></script>
<script src="/resource/js/circle-progress.js"></script>
<div class="clear h50"></div>
<div class="layout kj">
	<form name="borrowForm" id="borrowForm">
	<input type="hidden" id="ftype" name="ftype" value="<?php echo $ftype;?>">
	<input type="hidden" id="fastid" name="fastid" value="<?php echo $fastid;?>">
	<dl>
		<dt>
			<i class="t1"><img src="/resource/images/shu_line.png" width="5" height="25"></i>
            <h3>填写<?php echo $borrow_arr[$ftype];?>借款信息 <?php if($ftype == 3){?><span style="margin-left: 58px">您的净值借款额度为：<?php echo $net_amount?>元</span><?php }?></h3>
		</dt>
		<dd>
			<ul>
				<li>
					<span>借款信息：</span>
                    <select class="pubinput bl" id="fuse" name="fuse"><?php foreach($borrow_use as $key=>$value){?><option value="<?php echo $key;?>"><?php echo $value;?></option><?php }?></select>
				</li>
                <?php if($ftype != 5){?>
				<li>
					<span>借款期限：</span>
					<?php if($ftype != 3){?>
					<select class="pubinput" id="time_limit" name="time_limit" style="width:76px;">
						<?php foreach($borrow_time_limit as $key=>$value){?>
                    	<option value="<?php echo $key;?>"><?php echo $value;?></option>
						<?php }?>
                    </select>
					<?php }?>

					<?php if($ftype != 3){?>
					<div style="<?php if($ftype == 4){ ?>display:none;<?php }?>">
    				<s>按天</s> <input id="is_day" type="checkbox" value="1" name="is_day" class="gx">
 					<select id="time_limit_day" name="time_limit_day" style="display:none; width:76px;">
						<?php foreach($borrow_day_time_limit as $key=>$value){?>
						<option value="<?php echo $key;?>"><?php echo $value;?></option>
						<?php }?>
					</select>
					</div>
					<?php }else{?>
					<div style="<?php if($ftype == 4){?>display:none;<?php }?>">
					<s>按天</s> <input id="is_day" style="padding-top:5px;" type="checkbox" value="1" name="is_day" checked="checked" disabled="disabled">
					<select id="time_limit_day" name="time_limit_day">
						<?php foreach($borrow_day_time_limit as $key=>$value){?>
						<option value="<?php echo $key;?>"><?php echo $value;?></option>
						<?php }?>
					</select>
					</div>
                    <?php }?>
				</li>
				<?php if($ftype == 4){?>
				<li>
					<span>流转周期：</span>
					<select class="pubinput" id="lz_times" name="lz_times"><?php foreach($borrow_time_limit as $key=>$value){?><option value="<?php echo $key;?>"><?php echo $value;?></option><?php }?></select>
				</li>
				<li>
					<span>还款方式：</span>
					<select class="pubinput" id="style" name="style"><option value="3">到期还本，按月付息</option></select>
				</li>
				<?php }else{?>
				<li>
					<span>还款方式：</span>
					<select class="pubinput" id="style" name="style"><?php foreach($borrow_style  as $key=>$value){?><option value="<?php echo $key;?>"><?php echo $value;?></option><?php }?></select>
				</li>
				<?php }?>
                <?php }?>
				<li>
					<span>借贷总金额：</span>
                    <input class="pubinput miaob" type="text" id="account" name="account"/>
				</li>
				<li>
                    <span>年利率：</span>
                    <input class="pubinput miaob" type="text" id="apr" name="apr"/> <s>%</s>
				</li>
				<li>
                    <span>是否定向标：</span>
                    <input type="checkbox" id="is_dxb" name="is_dxb" value="1" class="gx" />
				</li>
				<li<?php if($ftype == 5){echo ' style="width:828px"'; }?>>
                    <span>定向标密码：</span>
                    <input class="pubinput miaob" type="text" id="dxb_pwd" name="dxb_pwd" disabled="disabled" />
				</li>
				<li>
                    <span><?php if($ftype != 4){?>最低投标金额<?php }else{?>每份金额<?php }?>：</span>
					<?php if($ftype == 4){?>
					<input class="pubinput miaob" type="text" id="lowest_account" name="lowest_account" value="100"><s>元</s>
					<?php }else{?>
					<input class="pubinput miaob" type="text" id="lowest_account" name="lowest_account" value="100"><s>元</s>
					<?php }?>
				</li>
				<li<?php if($ftype == 4){?> style="display:none;"<?php }?>  class="w458">
					<span>最多投标总额：</span>
					<input class="pubinput miaob" type="text" id="most_account" name="most_account" value="0">
                    <s>元(0表示不限)</s>
				</li>
				<li>
                    <span>有效时间：</span>
					<select id="valid_time" name="valid_time">
					<?php foreach($borrow_valid_time as $key=>$value){?>
					<option value="<?php echo $key;?>" <?php if($key==3){?>selected="selected"<?php }?> ><?php echo $value;?></option>
					<?php }?>
					</select>
				</li>
				<li>
                    <span>自动审核时间：</span>
                    <input type="text" id="auto_verify_time" name="auto_verify_time" class="pubinput miaob" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" readonly />
				</li>
				<li>
                    <span>开放购买时间：</span>
                    <input type="text" id="open_time" name="open_time" class="pubinput miaob" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" readonly />
				</li>
				<?php if($ftype == 7){?>
				<li>
                    <span>担保机构：</span>
					<select id="guarantee_id" class="pubinput" name="guarantee_id">
					<option value="0">   --请选择担保机构--</option>
					<?php foreach ($guarantee_list as $gv){?>
					<option value="<?php echo $gv['id']?>"><?php echo $gv['name']?></option>
					<?php }?>
					</select>
				</li>
                <?php }?>
			</ul>
		</dd>
	</dl>
    <dl>
		<dt>
			<i class="t1"><img src="/resource/images/shu_line.png" width="5" height="25"></i>
			<h3>投标奖励</h3>
		</dt>
        <dd>
           	<ul>
               	<li class="wz">
					<input type="radio" id="award" name="award" checked="checked" value="0" class="yuan">
					<i>不设置奖励</i>
                </li>
                <li>
                	<input type="radio" id="award" name="award" value="2" class="yuan" <?php if($ftype == 3){?>disabled="disabled"<?php }?>>
					<i>按投标金额比例奖励：</i>
                    <input class="pubput miaob-02" type="text" size="5" value="" name="funds" id="funds" <?php if($ftype == 3){?>disabled="disabled"<?php }?>>
					<i>%</i>
				</li>
			</ul>
		</dd>
	</dl>
	<dl>
		<dt>
			<i class="t1"><img src="/resource/images/shu_line.png" width="5" height="25"></i>
			<h3>个人信息</h3>
		</dt>
		<dd>
			<ul>
				<li>
					<span class="kd">公开我的帐户资金情况 </span>
                    <input type="checkbox" disabled="disabled" checked="checked" value="1" name="open_account" class="gx">
				</li>
				<li>
					<span class="kd">公开我的借款资金情况</span>
                    <input type="checkbox" disabled="disabled" checked="checked" value="1" name="open_account" class="gx">
				</li>
				<li class="w458">
					<span  class="kd">公开我的投标资金情况</span>
                    <input type="checkbox" checked="checked" value="1" name="open_tender" class="gx">
				</li>
				<li>
					<span class="kd">公开我的信用额度情况</span>
                    <input type="checkbox" disabled="disabled" checked="checked" value="1" name="open_account" class="gx">
				</li>
				<li>
					<span class="kd">公开我的证明资料情况</span>
                    <input type="checkbox" checked="checked" value="1" name="open_attestation" class="gx">
				</li>
			</ul>
		</dd>
	</dl>
	<dl>
		<dt>
			<i class="t1"><img src="/resource/images/shu_line.png" width="5" height="25"></i>
			<h3>投标说明</h3>
		</dt>
		<dd>
			<ul>
				<li>
					<span>标题：</span>
                    <input class="input miaob" type="text" id="title" name="title">
				</li>
				<li>
                    <span>标图片：</span>
					<input type="hidden" id="borrow_img" name="borrow_img" />
					<a href="javascript:;" class="up_file" style="margin-top: 10px;">选择文件
						<input hidefocus="true" type="file" id="thumbnail" name="thumbnail" onchange="ajaxFileUpload();">
					</a>
				</li>
				<li class="w458">
                    <span>概要：</span>
                    <input class="input miaob" type="text" id="summary" name="summary">
				</li>
				<li>
                    <span>经营范围：</span>
                    <input class="input miaob" type="text" id="business" name="business">
				</li>
				<li class="line">
                    <span>项目介绍：</span>
                    <textarea name="content" id="content" style="width:600px;height:200px;margin-bottom:10px;" class="ckeditor bian"></textarea>
				</li>
				<li class="line">
                    <span>还款来源：</span>
                    <textarea name="repay_from" id="repay_from" style="width:600px;height:200px;margin-bottom:10px;" class="ckeditor bian"></textarea>
				</li>
				<li class="line">
                    <span>风控措施：</span>
                    <textarea name="risk_manage" id="risk_manage" style="width:600px;height:200px;margin-bottom:10px;" class="ckeditor bian"></textarea>
				</li>
				<li class="line">
                    <span>发布说明：</span>
                    <textarea name="publish_remark" id="publish_remark" style="width:600px;height:200px;margin-bottom:10px;" class="ckeditor bian"></textarea>
				</li>
			</ul>
		</dd>
	</dl>
    <div class="clear h20"></div>
    <div style="margin:50px auto;width:300px;"><input type="button" class="button" value="立即申请" onclick="borrowSubmit();"></div>
    <div class="clear h20"></div>
</div>
<div class="clear h50"></div>
<?php include "./application/views/footer.php";?>
<script type="text/javascript">
    $(document).ready(function(){
        //净值标：还款方式只能是等额本息

        //是否勾选天标
        $("#is_day").click(function(){
            if($("#is_day").is(":checked")){
                $("#time_limit_day").show();
                $("#time_limit").attr("disabled",true);
                $("#time_limit").val(1);
                $("#style").val(0);
                $("#style").attr("disabled",true);
            }else{
                $("#time_limit_day").hide();
                $("#time_limit").attr("disabled",false);
                $("#style").attr("disabled",false);
            }
        });
        //是否启用定向标
        $("#is_dxb").click(function(){
            if($("#is_dxb").is(":checked")){
                $("#dxb_pwd").attr("disabled",false);
            }else{
                $("#dxb_pwd").attr("disabled",true);
            }
        });
        $("#borrow_btn").click(function(){
            $("#borrowForm").submit();
            $("#borrowForm").attr("disabled",true);
        });
    });

function ajaxFileUpload() {
        $.ajaxFileUpload
        (
            {
                url: '/borrow/uploadPicture.html', //用于文件上传的服务器端请求地址
                secureuri: false, //一般设置为false
                fileElementId: 'thumbnail', //文件上传空间的id属性  <input type="file" id="file" name="file" />
                dataType: 'text', //返回值类型 一般设置为json
                success: function (data, status)  //服务器成功响应处理函数
                {
                    if (data == '') {
                        alert('上传图片失败');
                    } else {
                        $('#borrow_img').val(data);
                    }
                },
                error: function (data, status, e)//服务器响应失败处理函数
                {
                    alert(e);
                }
            }
        )

    }


    function borrowSubmit(){
        var options = {
            url : '/borrow/publish_add/',
            //clearForm :true,
            //resetForm :true,
//            contentType:"multipart/form-data",
//            beforeSubmit:  publishCheckForm,
            dataType: "json",
            type:"post",
            success : function(ret) {
                if(ret.msg==''){
                    alert("借款申请成功，等待审核！");
                    location=ret.url;
                }else{
                    alert(ret.msg);
                }
            }
        };
        $("#borrowForm").ajaxSubmit(options);
        return false;
    }

    function publishCheckForm(){
        var err = '';

        //净值标利息：必须在5%-18%之间
                if(IsDouble($('#account').val())==false){
            err = '请填写有效的借款金额';
        }else if($('#account').val() < 500){
            err = '借款金额必须大于500';
        }else if($('#account').val() > 5000000){
            err = '借款金额必须小于500w';
        }else if(IsDouble($('#apr').val())==false){
            err = '请填写有效的年利率';
        }else if($('#apr').val()<=0 || $('#apr').val()>24){
            err = '年利率必须在0%-24%之间';
        }else if($('input[name="award"]:checked').val() == 2){
            if(IsDouble($('#funds').val())==false){
                err = '请填写有效的奖励';
            }
        }else if($('#title').val()==''){
            err = '请填写借款标题';
        }else if($('#content').val()==''){
            err = '请填写借款内容';
        }else if($('#title').val().length > 32){
            err = '借款标题过长';
        }
        if(err==''){
            return true;
        }else{
            alert(err);
            return false;
        }
    }

</script>
